﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using FlyHorse.LIMS.WinApp.Utils;
using FlyHorse.LIMS.WinApp.LanguageResource;
using FlyHorse.LIMS.Model;

namespace FlyHorse.LIMS.WinApp.OtherForms
{
    public partial class ChangePassWordForm : DevExpress.XtraEditors.XtraForm
    {
        BLL.LoginUserBll loginUserBll = new BLL.LoginUserBll();
        public ChangePassWordForm()
        {
            InitializeComponent();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            //判空
        
            string passwordOriginal = this.textEditOriginalPassword.Text;
            string passwordNew1 = this.textEditNewPassword1.Text;
            string passwordNew2 = this.textEditNewPassword2.Text;
            if (passwordNew1 != passwordNew2)
            {
                XtraMessageBox.Show(ResourceOverall.NewPasswordCompareErr);    //Two input do not match the new password!
                return;
            }
            if (passwordOriginal!=LoginUserUtil.LoginUser.Password)
            {
                XtraMessageBox.Show(ResourceOverall.OldPasswordErr);
                return;
            }
            else if (passwordOriginal==LoginUserUtil.LoginUser.Password)
            {
                LoginUserUtil.LoginUser.Password = passwordNew1;
                using (OJCB4Entities db =new OJCB4Entities())
                {
                    var user=  db.LoginUsers.Find(LoginUserUtil.LoginUser.LoginUserID);
                    user.Password = passwordNew1;
                    bool res = db.SaveChanges()>0;
                    if (res)
                    {
                        XtraMessageBox.Show(ResourceOverall.EditSucceed);
                        this.Close();
                    }
                }
                
            }
          

           
        }

        private void ChangePassWordForm_Load(object sender, EventArgs e)
        {

        }
    }
}